package com.example.hello.views;

import com.example.hello.*;
import com.example.hello.views.assignments.Assignments;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.server.FileResource;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Link;
import com.vaadin.ui.VerticalLayout;

import java.io.File;

public class Wireframe1 extends VerticalLayout implements View {

    public static final String NAME = "";

    BootstrapContainer container = new BootstrapContainer();

    @Override
    public void enter(ViewChangeListener.ViewChangeEvent event) {
    }

    public Wireframe1() {
        setSizeFull();

        initWireframe1();

        addComponent(container, 0);
    }

    public void initWireframe1() {
        BootstrapParagraph paragraph = new BootstrapParagraph();
        Heading header = new Heading("Hello", 1);
        BootstrapHero hero = new BootstrapHero(header);
        BootstrapRow row = new BootstrapRow();
        BootstrapColumn topAssignmentsColumn = new BootstrapColumn();
        BootstrapColumn recentBadgesColumn = new BootstrapColumn();
        BootstrapColumn recentEventsColumn = new BootstrapColumn();

        Heading assignment1 = new Heading(new AnchorHref("iOS Beginner - Assignment 1").toString(), 5);
        Heading assignment2 = new Heading(new AnchorHref("Drupal - Assignment 1").toString(), 5);
        Heading assignment3 = new Heading(new AnchorHref("Camel Fundamentals - Assignment 2").toString(), 5);
        Heading assignment4 = new Heading(new AnchorHref("SiteCore - Assignment 1").toString(), 5);
        Heading assignment5 = new Heading(new AnchorHref("Camel Fundamentals - Assignment 2").toString(), 5);

        Badge badge1 = new Badge("AG", "Android+Guru", "543210");
        Badge badge2 = new Badge("DG", "Drupal+Guru", "141414");
        Badge badge3 = new Badge("AJ", "Android+Journeyman", "012345");
        Badge badge4 = new Badge("CN", "Camel+Novice", "314253");
        Badge badge5 = new Badge("SJ", "Sitecore+Journeyman", "152637");
        Heading badge1text = new Heading("Andrew Hemby - " + badge1.getName(), 5);
        Heading badge2text = new Heading("Rob Tompkins - " + badge2.getName(), 5);
        Heading badge3text = new Heading("Sergio Angeles - " + badge3.getName(), 5);
        Heading badge4text = new Heading("Chris Wash - " + badge4.getName(), 5);
        Heading badge5text = new Heading("Jimmy Champion - " + badge5.getName(), 5);
        HorizontalLayout badge1layout = new HorizontalLayout(badge1, new HSpacer(5), badge1text);
        HorizontalLayout badge2layout = new HorizontalLayout(badge2, new HSpacer(5), badge2text);
        HorizontalLayout badge3layout = new HorizontalLayout(badge3, new HSpacer(5), badge3text);
        HorizontalLayout badge4layout = new HorizontalLayout(badge4, new HSpacer(5), badge4text);
        HorizontalLayout badge5layout = new HorizontalLayout(badge5, new HSpacer(5), badge5text);

        ParagraphHeading event1 = new ParagraphHeading("Chris Wash submitted Camel Fundamentals - " +
                new AnchorHref("Assignment 1"), 5);
        ParagraphHeading event2 = new ParagraphHeading("Andrew Hemby submitted Android Advanced - " +
                new AnchorHref("Assignment 3"), 5);
        ParagraphHeading event3 = new ParagraphHeading("Eric Miles reviewed Andrew Hemby's Android Advanced - " +
                new AnchorHref("Assignment 3 Submission"), 5);

        paragraph.setText("This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.");

        BootstrapButton learnMore = new BootstrapButton("Learn More", BootstrapButton.Type.PRIMARY, BootstrapButton.Size.LARGE);
        learnMore.addListener(new Listener() {
            @Override
            public void componentEvent(Event event) {
                getUI().getNavigator().navigateTo(Assignments.NAME);
            }
        });

        assignment1.setContentMode(ContentMode.HTML);
        assignment2.setContentMode(ContentMode.HTML);
        assignment3.setContentMode(ContentMode.HTML);
        assignment4.setContentMode(ContentMode.HTML);
        assignment5.setContentMode(ContentMode.HTML);

        badge1layout.setComponentAlignment(badge1, Alignment.MIDDLE_LEFT);
        badge1layout.setComponentAlignment(badge1text, Alignment.MIDDLE_LEFT);
        badge2layout.setComponentAlignment(badge2, Alignment.MIDDLE_LEFT);
        badge2layout.setComponentAlignment(badge2text, Alignment.MIDDLE_LEFT);
        badge3layout.setComponentAlignment(badge3, Alignment.MIDDLE_LEFT);
        badge3layout.setComponentAlignment(badge3text, Alignment.MIDDLE_LEFT);
        badge4layout.setComponentAlignment(badge4, Alignment.MIDDLE_LEFT);
        badge4layout.setComponentAlignment(badge4text, Alignment.MIDDLE_LEFT);
        badge5layout.setComponentAlignment(badge5, Alignment.MIDDLE_LEFT);
        badge5layout.setComponentAlignment(badge5text, Alignment.MIDDLE_LEFT);

        hero.addWidget(paragraph);
        hero.addWidget(learnMore);

        container.addWidget(hero);
        container.setHeight("600px");

        topAssignmentsColumn.addWidget(new BootstrapHeading("Top Assignments"));
        recentBadgesColumn.addWidget(new BootstrapHeading("Recent Badges"));
        recentEventsColumn.addWidget(new BootstrapHeading("Recent Events"));

        topAssignmentsColumn.setHeight("120px");
        topAssignmentsColumn.addWidget(new HorizontalLayout(new HSpacer(5), assignment1, new HSpacer(20)));
        topAssignmentsColumn.addWidget(new HorizontalLayout(new HSpacer(5), assignment2, new HSpacer(20)));
        topAssignmentsColumn.addWidget(new HorizontalLayout(new HSpacer(5), assignment3, new HSpacer(20)));
        topAssignmentsColumn.addWidget(new HorizontalLayout(new HSpacer(5), assignment4, new HSpacer(20)));
        topAssignmentsColumn.addWidget(new HorizontalLayout(new HSpacer(5), assignment5, new HSpacer(20)));

        recentBadgesColumn.setHeight("120px");
        recentBadgesColumn.addWidget(badge1layout);
        recentBadgesColumn.addWidget(badge2layout);
        recentBadgesColumn.addWidget(badge3layout);
        recentBadgesColumn.addWidget(badge4layout);
        recentBadgesColumn.addWidget(badge5layout);

        recentEventsColumn.setHeight("120px");
        recentEventsColumn.addWidget(event1);
        recentEventsColumn.addWidget(new VSpacer(20));
        recentEventsColumn.addWidget(event2);
        recentEventsColumn.addWidget(new VSpacer(20));
        recentEventsColumn.addWidget(event3);

        row.addWidget(topAssignmentsColumn);
        row.addWidget(recentBadgesColumn);
        row.addWidget(recentEventsColumn);

        container.addWidget(row);

        File rss = new File(HelloUI.resourceLocation + "/WEB-INF/classes/article.rss");
        addComponent(new Link("rss", new FileResource(rss)));
    }

}
